﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;


/// <summary>
/// Summary description for LoaiCD
/// </summary>
public class LoaiCD
{
	public LoaiCD()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    DataConnection data = new DataConnection();
    public DataTable LayLoaiCD()
    {
        string sql = "select * from LoaiCD";
        return data.GetData(sql);
    }
    public DataTable SuaLoaiCD(int ma,string ten,float  gia,float  tienphat)
    {
        SqlParameter p1 = new SqlParameter("@Ten", ten);
        SqlParameter p2 = new SqlParameter("@Giathue", gia);
        SqlParameter p3 = new SqlParameter("@Tienphat", tienphat);
        SqlParameter p4 = new SqlParameter("@Ma", ma);
        string sql = "update LoaiCD set TenLoai=@Ten,GiaThue=@GiaThue,Tienphat=@TienPhat where MaLoai=@Ma";
        return data.GetData(sql, p1, p2, p3, p4);
    }
    public DataTable Xoa(int mal)
    {
       

        SqlParameter p = new SqlParameter("@Ma", mal);
        string sql = "Delete from LoaiCD  where MaLoai=@Ma";
        
        return data.GetData(sql, p);
    }
    //public DataTable XoaLoaiCD(string ma)
    //{
    //    SqlParameter p = new SqlParameter("@MaLoai", ma);
    //    string sql ="delete from LoaiCD from CD where LoaiCD.MaLoai=@MaLoai";
    //    return data.GetData(sql, p);
    //}
    public DataTable ThemLoaiCD( string ten, float  gia, float  tienphat)
    {
        
        SqlParameter p2 = new SqlParameter("@TenLoai", ten);
        SqlParameter p3 = new SqlParameter("@GiaThue", gia);
        SqlParameter p4 = new SqlParameter("@TienPhat", tienphat);
        string sql = "insert into LoaiCD values(@TenLoai,@GiaThue,@TienPhat)";
        return data.GetData(sql, p2, p3, p4);
    }
    public DataTable TimLoaiCD(string ten,string  tu,string den)
    {
        string sql = "select * from LoaiCD where 1=1";
       // string sql = "select * from LoaiCD where GiaThue between @tu and @den or TenLoai like '%'+@ten+'%'";
        //if (ten != null)
        //    sql = sql + " and TenLoai like '%'+@TenLoai+'%'";
        if (ten != null)
            sql = sql + " and TenLoai like '%'+@ten+'%'";
        if (tu != null && den != null)
            sql = sql + " or GiaThue between @tu and @den";
        SqlParameter p = new SqlParameter("@ten", ten);
        SqlParameter p1 = new SqlParameter("@tu", tu);
        SqlParameter p2 = new SqlParameter("@den", den);
        return data.GetData(sql, p, p1,p2);
    }
    
   
}
